﻿using System;
using Com.PhilChuang.Pmvp.Ui.Views.Impl.Pages;
using Com.PhilChuang.Pmvp.Ui.Views.Impl.ViewModels;
using Com.PhilChuang.Utils;

namespace Com.PhilChuang.Pmvp.Ui.Views.Impl.ViewFacades
{
	public class AboutViewFacade : AbstractViewFacade<AboutPage, AboutPageViewModel>, IAboutView
	{
		#region Events
		public event Action DoLaunchAppRateLink = delegate { }; 
		public event Action DoOpenSendFeedbackView = delegate { };
		public event Action DoLaunchAppWebsiteLink = delegate { };
		//public event Action DoLaunchDonateLink = delegate { };
		#endregion

		#region Instance Variables (EMPTY)
		#endregion

		#region Properties
		public VersionInfo VersionInfo
		{
			get { return myViewModel.VersionInfo; }
			set
			{
				if (DoNotAccessViewModel ()) return;
				InvokeSet (val => {
				           	if (DoNotAccessViewModel ()) return;
				           	myViewModel.HasBeenLoaded = true;
				           	myViewModel.VersionInfo = val;
				           },
				           value);
			}
		}

		public String HelpContent
		{
			get { return myViewModel.HelpContent; }
			set
			{
				if (DoNotAccessViewModel ()) return;
				InvokeSet (val => {
				           	if (DoNotAccessViewModel ()) return;
				           	myViewModel.HasBeenLoaded = true;
				           	myViewModel.HelpContent = val;
				           },
				           value);
			}
		}

		//public bool ShowDonateLink
		//{
		//    get { return myViewModel.ShowDonateLink; }
		//    set
		//    {
		//        InvokeSet (val => {
		//                    myViewModel.HasBeenLoaded = true;
		//                    myViewModel.ShowDonateLink = val;
		//                   },
		//                   value);
		//    }
		//}
		#endregion

		#region Constructors
		public AboutViewFacade ()
		{
			Init (false);
		}

		public AboutViewFacade (AboutPage page)
		{
			myPage = page;
			Init (true);
		}

		private void Init (bool wireUp)
		{
			myViewModel = new AboutPageViewModel ();
			myViewModel.IsAssociatedWithViewFacadeAndPage = true;
			myViewModel.HasBeenLoaded = false;
			if (wireUp) WireUpPage ();
		}
		#endregion

		/// <summary>
		/// Unsubscribes view event handlers.
		/// Call base impl as last step.
		/// </summary>
		protected override void UnWirePage ()
		{
			if (myPage == null) return;

			// IAboutView
			myPage.DoLaunchAppRateLink -= FireDoLaunchAppRateLink;
			myPage.DoOpenSendFeedbackView -= FireDoOpenSendFeedbackView;
			myPage.DoLaunchAppWebsiteLink -= FireDoLaunchAppWebsiteLink;

			base.UnWirePage ();
		}

		/// <summary>
		/// Subscribes view event handlers.
		/// Call base impl as first step.
		/// </summary>
		protected override void WireUpPage ()
		{
			if (myPage == null) return;

			base.WireUpPage ();

			// IAboutView
			myPage.DoLaunchAppRateLink += FireDoLaunchAppRateLink;
			myPage.DoOpenSendFeedbackView += FireDoOpenSendFeedbackView;
			myPage.DoLaunchAppWebsiteLink += FireDoLaunchAppWebsiteLink;
		}

		protected void FireDoLaunchAppRateLink ()
		{ DoLaunchAppRateLink (); }
		protected void FireDoOpenSendFeedbackView ()
		{ DoOpenSendFeedbackView (); }
		protected void FireDoLaunchAppWebsiteLink ()
		{ DoLaunchAppWebsiteLink (); }
	}
}
